#include "stdafx.h"
#include "ClientDataManage.h"
#include "ClientDlg.h"

CClientDataManage::CClientDataManage(void)
{
}


CClientDataManage::~CClientDataManage(void)
{
}


void CClientDataManage::afterConnectServer(PerIoData*)
{

}




void CClientDataManage::afterRecvData(PerIoData * p)
{


	PPackageHead pstHead = (PPackageHead)p->getMsg();

	switch (pstHead->nType)
	{
	case TYPE_COMMAND:
		RecvCommand(p);
	default:
		break;
	}


}

void CClientDataManage::RecvCommand(PerIoData* pData)
{

	CProcess process;
	CClientDlg* dlg = (CClientDlg*)AfxGetApp()->m_pMainWnd;

	PROCESS_INFO_NET_ALL stAllInfo = {0};
	PackageHead stHead = {0};
	PerIoData* data;


	PPackageHead pstHead = (PPackageHead)pData->getMsg();
	Package pack = {0};
	int x = sizeof(pack);
		switch (pstHead->dwCommand)
	{
	case REQUEST_PROCESS:
		//stHead.dwCommand = RESPOND_PROCESS;
		//stHead.nType = TYPE_COMMAND;
		//SendHead(stHead);

		process.UpgradeProcessPrivilege();
		process.ReadSystemProcessInfo();
		stAllInfo = process.GetAllProcessInfo_NET();

		pack.dwCommand = RESPOND_PROCESS;
		pack.info.stAllInfo = stAllInfo;

		data = new PerIoData(sizeof(pack), (char*)&pack);
		dlg->GetClientSocket()->cSend(data);

		break;

	default:
		break;
	}


}


void CClientDataManage::SendHead(PackageHead stHead)
{
	CClientDlg* dlg = (CClientDlg*)AfxGetApp()->m_pMainWnd;
	PerIoData* pData;
	pData = new PerIoData(sizeof(stHead), (char*)&stHead);
	dlg->GetClientSocket()->cSend(pData);
	delete pData;
}
